package com.richie696.catalina;

import com.richie696.connect.http11.RequestMethod;

import java.io.InputStream;
import java.util.*;

public class ApplicationHttpRequest implements HttpServletRequest {

    private final InputStream inputStream;
    private final Header header;

    public ApplicationHttpRequest(InputStream inputStream, Header header) {
        this.inputStream = inputStream;
        this.header = header;
    }

    @Override
    public String getParameter(String name) {
        return String.join(",", this.header.getParameters().get(name));
    }

    @Override
    public InputStream getInputStream() {
        return this.inputStream;
    }

    @Override
    public Enumeration<String> getParameterNames() {
        return Collections.enumeration(this.header.getParameters().keySet());
    }

    @Override
    public String[] getParameterValues(String name) {
        return this.header.getParameters().get(name);
    }

    @Override
    public Map<String, String[]> getParameterMap() {
        return this.header.getParameters();
    }

    @Override
    public String getProtocol() {
        return this.header.getProtocol();
    }

    @Override
    public String getScheme() {
        return this.header.getScheme();
    }

    @Override
    public String getServerName() {
        return this.header.getHost();
    }

    @Override
    public int getServerPort() {
        return this.header.getPort();
    }

    @Override
    public String getRemoteAddr() {
        return this.header.getHost();
    }

    @Override
    public String getRemoteHost() {
        return this.header.getHost();
    }

    @Override
    public Locale getLocale() {
        return this.header.getLocale();
    }

    @Override
    public String getHeader(String name) {
        return this.header.getHeader(name);
    }

    @Override
    public Enumeration<String> getHeaderNames() {
        return Collections.enumeration(this.header.getParameters().keySet());
    }

    @Override
    public String getMethod() {
        return this.header.getMethod().name();
    }

    @Override
    public RequestMethod getRequestMethod() {
        return this.header.getMethod();
    }

    @Override
    public String getQueryString() {
        return this.header.getQueryString();
    }


}
